package com.example.yyg.springframework.beans.factory.support;

import com.example.yyg.springframework.core.io.DefaultResourceLoader;
import com.example.yyg.springframework.core.io.Resource;
import com.example.yyg.springframework.core.io.ResourceLoader;

/**
 * @Author: 冰岩
 * @Date: 2023/07/05
 * @Description:
 */
public abstract class AbstractBeanDefinitionReader implements BeanDefinitionReader{

    BeanDefinitionRegistry beanDefinitionRegistry;

    ResourceLoader resourceLoader;

    public AbstractBeanDefinitionReader(BeanDefinitionRegistry beanDefinitionRegistry) {
        this(beanDefinitionRegistry, new DefaultResourceLoader());
    }

    public AbstractBeanDefinitionReader(BeanDefinitionRegistry beanDefinitionRegistry, ResourceLoader resourceLoader) {
        this.beanDefinitionRegistry = beanDefinitionRegistry;
        this.resourceLoader = resourceLoader;
    }

    @Override
    public BeanDefinitionRegistry getRegistry() {
        return beanDefinitionRegistry;
    }

    @Override
    public ResourceLoader getResourceLoader() {
        return resourceLoader;
    }

    @Override
    public void loadBeanDefinition(String path) {
        Resource resource = resourceLoader.getResource(path);
        loadBeanDefinition(resource);
    }


    @Override
    public void loadBeanDefinition(Resource... resources) {
        for (Resource resource:resources) {
            loadBeanDefinition(resource);
        }
    }
}
